package railRoad.dao.interfaces;

import railRoad.exception.DBException;

/**
 * DAO interface for routine with database
 * @author Rukin
 *
 */
public interface IDAO<T> {
	/**
	 * Select T from database by it id
	 * 
	 * @param id
	 *            id parameter to search
	 * @return result of select
	 * @throws DBException
	 */
	T select(int id) throws DBException;
	
	
	/**
	 * Select T from database by it unique field
	 * 
	 * @param field
	 *            value of unique parameter
	 * @return result of select
	 * @throws DBException
	 */
	T select(String field) throws DBException;
	
	/**
	 * Insert new object into database
	 * @param insertObject object to insert
	 * @param parrentId foreign key if need
	 * @return 1 if inserted else -1
	 * @throws DBException
	 */
	int insert(T insertObject, int parrentId) throws DBException;
	
	/**
	 * update object in database
	 * @param updatedObject updated object
	 * @return 1 if updated else -1
	 * @throws DBException
	 */
	int update(T updatedObject) throws DBException;
	
	/**
	 * delete object from database
	 * @param removedObject object to delete
	 * @return  0 if deleted else -1
	 * @throws DBException
	 */
	int delete(T removedObject) throws DBException;
}
